/**
 * Created by Daniel on 7/11/16.
 */
import alt from '../alt';

class FooterActions {
    /**
     * 注册actions到strore中,每个action对应store的一个onActionName的函数.
     *
     */
    constructor() {
        this.generateActions(
            'getTopCharactersSuccess',
            'getTopCharactersFail'
        );
    }

    /**
     * 这里Ajax获取到数据以后将结果传给actions,然后store的对应bindAction的监听函数(onActionName)就会拿到.
     *
     */
    getTopCharacters() {
        $.ajax({ url: '/api/characters/top' })
            .done((data) => {
                this.actions.getTopCharactersSuccess(data)
            })
            .fail((jqXhr) => {
                this.actions.getTopCharactersFail(jqXhr)
            });
    }
}

export default alt.createActions(FooterActions);